var arr = new Array();
$(function() {
	initTileFn();
	
	if (arr[1] != undefined) {// tag1是发言
		var tag = arr[1].split("_")[2];
		var title1 = arr[1].split("_")[1];
		
		if (tag == 1) {
		$("#countP").html(getCount(2) + "条发言")
		
		} else if (tag == 2) {
		$("#countP").html(getCount(1) + "人签到")
		
		}
		if (tag == 3) {
		$("#countP").html("");
		}
	}
		//$("#title").html(title1);
		if($.trim(title1).length<1)
		{
		title1="关注微信号，发送含有“签到”两字的内容即可签到";
		}
		splits(title1);
	
	// 初始化气泡提示
	var toolTxt;
	$('.tooltip').mouseover(function() {
		var toolTxt = $(this).attr("title")
	}).tooltipster({
		content : toolTxt,
		theme : 'tooltipster-shadow',
		trigger : 'hover',
		delay : 0,
		speed : 200
	});
	var strStart = "<script src='/wxscreen/web/js/", strEnd = ".js'></script>";
	$("div.btnMenu a")
			.click(
					function() {
						
						var boxClass = $(this).attr("data-class");
						$("." + boxClass).show().siblings().hide();
						initTileFn();
						//clearInterval(timerMsg);
						//clearTimeout(timerSigin);
						switch (boxClass) {
						case "skinSelect": {
							skinSelectFn();
							break;
						}
						case "siginWall": {
							// 签到1
							siginWallFn();
							break;
						}
						case "msgWall": {
							// 留言2
							msgWallFn();
							break;
						}
						case "lotteryWall": {
							// 抽奖3
							lotteryWallFn();
							break;
						}
						case "voteWall": {
							// 投票4
							voteWallFn();
							break;
						}
						case "pairWall": {
							// 对对碰5
							pairWallFn();
							break;
						}
						case "onSiteWall":{
							onSiteWllFn();
							break;
						}
						case "fullWall":{
							break;
						}
						default:
							break;
						}
					});
	//快捷键
	document.onkeypress=function(event){
				 var e = event || window.event;
		       var keyCode = e.keyCode || e.which;
       			$.ajaxSetup({
					async : false
				});
				$.getJSON("/pc/head_getCurrPage.do", function(data) {
					$.each(data.headmessage, function(i, item) {
						arr[item.wallid] = item.wallid + "_"
								+ item.title + '_' + item.tag;
					});
				});
        switch (keyCode) {
           case 102:
               //f
               $(".skinSelect").show().siblings().hide();
               skinSelectFn();
               break;
           case 70:
           	//F
           	$(".skinSelect").show().siblings().hide();
           	skinSelectFn();
          		break;
           case 113:
               //q
                $(".siginWall").show().siblings().hide();
                siginWallFn();
               break;
           case 81:
               //Q
                $(".siginWall").show().siblings().hide();
                siginWallFn();
               break;
           case 109:
           	//m
           	 $(".msgWall").show().siblings().hide();
           	 msgWallFn();
          		break;
          	case 77:
           	//M
           	 $(".msgWall").show().siblings().hide();
           	 msgWallFn();
          		break;
           case 99:
           	//c
           	 $(".lotteryWall").show().siblings().hide();
           	 lotteryWallFn();
           	break;
   	    case 67:
           	//C
           	 $(".lotteryWall").show().siblings().hide();
           	 lotteryWallFn();
           	break;
       	case 116:
       		//t
       		 $(".voteWall").show().siblings().hide();
       		 voteWallFn();
       		break;
   		case 84:
       		//T
       		 $(".voteWall").show().siblings().hide();
       		 voteWallFn();
       		break;
       	case 100:
           	//d
           	 $(".pairWall").show().siblings().hide();
           	 pairWallFn();
           	break;
       	case 68:
           	//d
           	 $(".pairWall").show().siblings().hide();
           	 pairWallFn();
           	break;
       	case 120:
       		//x
       		 $(".onSiteWall").show().siblings().hide();
       		 onSiteWllFn();
       		break;
   		case 80:
       		//x
       		 $(".onSiteWall").show().siblings().hide();
       		 onSiteWllFn();
       		break;
           default:
               break;
        }	
	}
	function initTileFn(){

		$.ajaxSetup({
			async : false
		});
		$.getJSON("/pc/head_getCurrPage.do", function(data) {
			$.each(data.headmessage, function(i, item) {
				arr[item.wallid] = item.wallid + "_"
						+ item.title + '_' + item.tag;
			});
		});
	}
	//换肤
	function skinSelectFn(){
		var url = "skinCheckV1.0", allStr = strStart + url
		+ strEnd;
		$("body").append(allStr);
		var title1="关注微信号，发送含有“签到”两字的内容即可签到";
	   splits(title1);
	}
	//签到
	function siginWallFn(){
		var title1="关注微信号，发送含有“签到”两字的内容即可签到";
		if (arr[1] != undefined) {// tag1是发言
		var tag = arr[1].split("_")[2];
		if($.trim(arr[1].split("_")[1]).length>=1)
		{
			var title1 = arr[1].split("_")[1];
		}
		if (tag == 1) {
		$("#countP").html(getCount(2) + "条发言")
		
		} else if (tag == 2) {
		$("#countP").html(getCount(1) + "人签到")
		}
		if (tag == 3) {
		$("#countP").html("");
		}
		}
		splits(title1);
		$("body").append(strStart +"signWallV1.0"+ strEnd);
		siginWallInit();
	}
	//留言
	function msgWallFn(){
		changeWall(2);
		var title2="关注微信号，发送“我要上墙“开启上墙模式后，发送想要留言的内容即可上墙";
		if (arr[2] != undefined) {
			var tag = arr[2].split("_")[2];
			if(arr[2].split("_")[1].length>=1){
				title2=arr[2].split("_")[1];
			}
			if (tag == 1) {
				$("#countP").html(getCount(2) + "条发言")

			} else if (tag == 2) {
				$("#countP").html(getCount(1) + "人签到")
			}
			if (tag == 3) {
				$("#countP").html("");
			}

		}
		splits(title2);
	}
	//抽奖
	function lotteryWallFn(){
		var title="关注微信号，发送含有“签到”两字的内容即可签到";
		if (arr[3] != undefined) {
		var tag = arr[3].split("_")[2];
		if($.trim(arr[3].split("_")[1]).length>=1)
		{
			var title = arr[3].split("_")[1];
		}
		if (tag == 1) {
		$("#countP").html(getCount(2) + "条发言")
		
		}
		if (tag == 2) {
		$("#countP").html(getCount(1) + "人签到")
		}
		if (tag == 3) {
		$("#countP").html("");
		}
		}
		splits(title);
		var url = "luck/luck", allStr = strStart + url
		+ strEnd;
		
		$("body").append(allStr);
		progressLuckBar();
	}	//投票
	function voteWallFn(){
		progressBar();
		var title="关注微信号，发送含有“签到”两字的内容即可签到";;
			if (arr[6] != undefined) {
				var tag = arr[6].split("_")[2];
				if($.trim(arr[6].split("_")[1]).length>=1)
				{
					var title = arr[6].split("_")[1];
				}
				if (tag == 1) {
					$("#countP").html(getCount(2) + "条发言")
				}
				if (tag == 2) {
					$("#countP").html(getCount(1) + "人签到")
				}
				if (tag == 3) {
					$("#countP").html("");
				}
			}
			splits(title);
			var url = "voteWallV1.0", 
			allStr = strStart + url+ strEnd;
			$(".body").append(allStr);
		}
	//对对碰
	function pairWallFn(){
		var title="关注微信号，发送含有“签到”两字的内容即可签到";
		if (arr[5] != undefined) {

			var tag = arr[5].split("_")[2];
			//$("#title").html(title);
			if($.trim(arr[5].split("_")[1]).length>=1)
			{
				var title = arr[5].split("_")[1];
			}
			if (tag == 1) {
				$("#countP").html(getCount(2) + "条发言")
			}
			if (tag == 2) {
				$("#countP").html(getCount(1) + "人签到")
			}
			if (tag == 3) {
				$("#countP").html("");
			}
		}
		splits(title);
		var url = "pairWallV1", 
		allStr = strStart + url	+ strEnd;
		$(".body").append(allStr);
		progressPairBar();
	}
	//现场互动
	function onSiteWllFn(){
		var title="关注微信号，发送含有“签到”两字的内容即可签到";
		progressInteract();
		if (arr[4] != undefined) {
			var tag = arr[4].split("_")[2];
			
			if($.trim(arr[4].split("_")[1]).length<1)
			{
				var title = arr[4].split("_")[1];
			}
			if (tag == 1) {
				$("#countP").html(getCount(2) + "条发言")
			}
			if (tag == 2) {
				$("#countP").html(getCount(1) + "人签到")
			}
		}
		splits(title);
		
	}
					
					
	// 留言墙
	/**
	 * $(".msgWall li").on({ mouseenter : function() {
	 * $(this).find(".detailBtn").show(); }, mouseleave : function() {
	 * $(this).find(".detailBtn").hide(); }, click : function() {
	 * clearInterval(timerMsg); $(".msgWall").fadeOut("fast");
	 * $(".msgDetail").slideDown(); } })
	 */
	$(".msgDetail").on({
		mouseenter : function() {
			$(this).find(".msgClose").show();
		},
		mouseleave : function() {
			$(this).find(".msgClose").hide();
		}
	})
	$(".msgClose").on("click", function() {
		timerMsg = setInterval(msgWall, 2000);
		$(".msgDetail").hide();
		$(".msgWall").fadeIn();
	})
	/**
	 * var scrollHei=$(".msgWall").height(); var timerMsg; timerMsg =
	 * setInterval(msgWall, 2000); function msgWall() { $(".msgWall
	 * ul").animate({ "marginTop" : -scrollHei }, 1000, function() { $(".msgWall
	 * li").slice(0, 3).appendTo(".msgWall ul"); $(".msgWall
	 * ul").css("marginTop", 0) }); }
	 */
	function splits(title){
		var msgs='';
		 $("#title").siblings().remove();
		 $("#title li").remove();
		for(var i=0; i<=title.length;)
			{
			var msgs1=title.substring(i,i+17);
			var msgs2=title.substring(i+17,i+34);
			  $("#title").append('<li>'+msgs1+'<br>'+msgs2+'</li>');
			  i+=34;
			}
	}
})